<?php
namespace app\api\controller;

use app\BaseController;
class Auth extends BaseController{

	public function handle($request,\Closure $next){echo 11;exit;
		if(!$this->isLogin()){
			return show(config('status.not_login'),'未登录');
		}
		$response = $next($request);
		return $response;
	}

	public function isLogin(){
		$accessToken = request()->header('access_token');
		if(empty($accessToken)){
			return false;
		}else{
			$userInfo = cache(config('redis.token_pre').$this->accessToken);
			if(empty($userInfo)){
				return false;
			}
			if(!empty($userinfo['id']) && !empty($userinfo['username'])){
				//$this->username = $userinfo['username'];
				//$this->userId = $userinfo['id'];
				return true;
			}
		}
	}
}